//
//  ChangePasswordViewController.m
//  HongFuShop
//
//  Created by chirui on 2017/8/11.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "ChangePasswordViewController.h"

@interface ChangePasswordViewController ()
@property (weak, nonatomic) IBOutlet UITextField *oldPasswordText;
@property (weak, nonatomic) IBOutlet UITextField *curryText;
@property (weak, nonatomic) IBOutlet UITextField *sureText;
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;

@end

@implementation ChangePasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    TitleView(@"修改密码");
    self.sureBtn.layer.cornerRadius = 45/2.f;
    self.sureBtn.layer.masksToBounds = YES;
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_public_return" target:self action:@selector(back)];
    
    
}

-(void)back{
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (IBAction)sureBtnClick:(id)sender {
    
    if (_oldPasswordText.text.length==0||_oldPasswordText.text==nil) {
        
        SHuiMBhudTextTimeStr(@"原密码不能为空");
        return;
        
    }else if(_curryText.text.length<6){
        [SHJudgeTools MBProgressHUDPromptWith:@"密码不能少于6位" On:self.view];
        return;
    }else if (![_curryText.text isEqualToString:_sureText.text]){
        
        [SHJudgeTools MBProgressHUDPromptWith:@"两次密码不一致" On:self.view];
        return;
        
    }else {
        
        [self changePwdNetWorking];
    }

    
}

-(void)changePwdNetWorking{
    NSString * parametersStr = [NSString stringWithFormat:@"%@%@",NetWorkAddress_api,change_pwd_api];
    NSDictionary * parameter = @{@"phone":USER_DEFAULTGet(@"phone"),
                                 @"oldpwd":_oldPasswordText.text,
                                 @"newpwd":_curryText.text
                                 };
    NSLog(@"param ==%@",parameter);
    
    SHuiMBhubNoTimeStr(@"正在发送");
    [PostNetWorking postNetWorkingStr:parametersStr  andparameters:parameter  Success:^(id responseObject) {
        SHuiMBHidleYes;
        if ([responseObject[@"code"] intValue]==200) {
            SHuiMBhudTextTimeStr(@"修改成功,请重新登录");
            
            USER_DEFAULTSet(@"", @"token");
            USER_DEFAULTSet(@"", @"enter");
            USER_DEFAULTSet(@"", @"tokenVerify");
            USER_DEFAULTSet(@"", @"user_id");
            USER_DEFAULTSet(@"", @"phone");
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                LogingViewController * log =[[LogingViewController alloc]init];
                [self.navigationController pushViewController:log animated:YES];
                
            });
            
        } else {
            
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
    } failed:^(NSError *error) {
        
        SHuiMBHidleYes;
        SHuiMBhudTextTimeStr(@"请检查您的网络!");
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
